package com.nisco.dms.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.nisco.dms.entity.SqlColumn;
import com.nisco.dms.entity.SqlTable;
import com.nisco.dms.repository.SqlColumnDao;
import com.nisco.dms.util.dwz.Page;
import com.nisco.dms.util.dwz.PageUtils;

/**
 * 
 * @author Robin
 * 
 */
@Component
@Transactional(readOnly = true)
public class SqlColumnService extends BaseService<SqlColumn, String> {

	private SqlColumnDao sqlColumnDao;

	public SqlColumnService() {

	}

	@Autowired
	public SqlColumnService(SqlColumnDao sqlColumnDao) {
		super(sqlColumnDao);
		this.sqlColumnDao = sqlColumnDao;
	}

	@Autowired
	public void setSqlColumnDao(SqlColumnDao sqlColumnDao) {
		this.sqlColumnDao = sqlColumnDao;
	}

	/**
	 * 查询分页
	 * 
	 * @param compId
	 * @param page
	 * @return
	 */
	public List<SqlColumn> find(String colName, Page page) {
		org.springframework.data.domain.Page<SqlColumn> p = sqlColumnDao
				.findByColNameContaining(colName,
						PageUtils.createPageable(page));
		PageUtils.injectPageProperties(page, p);
		return p.getContent();
	}

	/**
	 * 根据数据表查询
	 * @param sqlTable
	 * @param page
	 * @return
	 */
	public List<SqlColumn> findBySqlTable(SqlTable sqlTable, Page page){
		org.springframework.data.domain.Page<SqlColumn> p = sqlColumnDao
				.findBySqlTable(sqlTable, PageUtils.createPageable(page));
		PageUtils.injectPageProperties(page, p);
		return p.getContent();
	}
	
	/**
	 * 根据主表查询字段，不分页
	 * @param sqlTable
	 * @return
	 */
	public List<SqlColumn> findBySqlTable(SqlTable sqlTable){
		return sqlColumnDao.findBySqlTable(sqlTable);
	}
	
}
